package com.uisian.serviceipml;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uisian.mapper.PopleMapper;
import com.uisian.mapper.PyMapper;
import com.uisian.pojos.Py;
import com.uisian.service.DgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DgServiceImpl extends ServiceImpl<PyMapper,Py> implements DgService {
    @Autowired
    private PopleMapper popleMapper;
    @Autowired
    private PyMapper pyMapper;
    @Override
    public String dg(Py py) {
        if (py.getPid() == null) {
            return "请输入手机号";
        }
        if (py.getYid()== null) {
            return "请选择你要订购的套餐";
        }
        //查询是否有套餐
        LambdaQueryWrapper<Py> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(Py::getPid, py.getPid());
        List<Py> list = list(wrapper);
        try {
            if (list==null){
                //这是订购套餐
                pyMapper.insert(py);
            }else {
                //这是更改套餐

            }
            return "订购成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "订购失败";
        }
    }
}
